package com.gs.SynPatrolRep.presenter;


import com.google.gson.reflect.TypeToken;
import com.gs.SynPatrolRep.apiresult.ApiResultData;
import com.gs.SynPatrolRep.apiresult.PagedList;
import com.gs.SynPatrolRep.db.dto.CreatePalBillEventResultDto;
import com.gs.SynPatrolRep.db.dto.PalBillEventDto;
import com.gs.SynPatrolRep.db.dto.PalBillSiteDto;
import com.gs.SynPatrolRep.db.query.BaseQuery;
import com.gs.SynPatrolRep.model.PalBillEventModel;
import com.gs.SynPatrolRep.model.PalBillModel;
import com.gs.SynPatrolRep.model.listener.OnResultListener;
import com.gs.SynPatrolRep.view.IPalBillSiteListView;

public class PalBillSiteListPresenter extends BasePresenter<IPalBillSiteListView> {
    private PalBillModel palBillModel = new PalBillModel();
    private PalBillEventModel model = new PalBillEventModel();

    public void getData(BaseQuery query) {
        getView().showLoading();
        palBillModel.getPalBillsSites(query, new OnResultListener() {
            @Override
            public void onSuccess(Object apiResult) {
                if (getView() != null) {
                    getView().onGetDataSuccess((ApiResultData<PagedList<PalBillSiteDto>>) apiResult);
                    getView().hideLoading();
                }
            }

            @Override
            public void onFails(Exception e) {
                if (getView() != null) {
                    getView().onGetDataFails(e);
                    getView().hideLoading();
                }
            }
        }, new TypeToken<ApiResultData<PagedList<PalBillSiteDto>>>() {
        }.getType());
    }

    public void getData(String id) {
        model.getData(id, new OnResultListener() {
            @Override
            public void onSuccess(Object apiResult) {
                if (getView() != null) {
                    getView().onGetDataIdSuccess((ApiResultData<PalBillEventDto>) apiResult);
                }
            }

            @Override
            public void onFails(Exception e) {
                if (getView() != null) {
                    getView().onGetDataIdFail(e);
                }
            }
        }, new TypeToken<ApiResultData<PalBillEventDto>>() {
        }.getType());
    }

    public void setResult(CreatePalBillEventResultDto bean){
        model.setResult(bean, new OnResultListener() {
            @Override
            public void onSuccess(Object aipResult) {
                if (getView() != null) {
                    getView().onSetResultSuccess((ApiResultData<String>) aipResult);
                }
            }

            @Override
            public void onFails(Exception e) {
                if (getView() != null) {
                    getView().onSetResultFail(e);
                }
            }
        }, new TypeToken<ApiResultData<String>>() {
        }.getType());
    }
}
